package pub

import (
	"os"

	"gopkg.in/yaml.v3"
)

type ConfigStc struct {
	ServerPort string `yaml:"server_port"`
	JwtSecret  string `yaml:"jwt_secret"`
}

var conf *ConfigStc

func InitConf() {
	var err error
	confFile, err := os.ReadFile("./config/config.yaml")
	if err != nil {
		panic("Can't open config file, please confirm config file is exists.")
	}
	err = yaml.Unmarshal(confFile, &conf)
	if err != nil {
		panic("Can't parse config file, please check config file.")
	}
}

func Conf() *ConfigStc {
	if conf == nil {
		panic("Load config file failed, please check config file is exists.")
	}
	return conf
}
